package com.stylefeng.guns.modular.vpn_operation_log.service.impl;

import com.stylefeng.guns.core.common.constant.DatasourceEnum;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.modular.system.dao.VpnOperationLogMapper;
import com.stylefeng.guns.modular.vpn.entity.VpnOperationLog;
import com.stylefeng.guns.modular.vpn.vo.Paging;
import com.stylefeng.guns.modular.vpn_operation_log.service.IVpnOperationLogService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 业务操作日志 服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2020-04-20
 */
@Service
public class VpnOperationLogServiceImpl extends ServiceImpl<VpnOperationLogMapper, VpnOperationLog> implements IVpnOperationLogService {
    @Autowired
    private VpnOperationLogMapper operationLogMapper;

    @Override
    @DataSource(name = DatasourceEnum.DATA_SOURCE_BIZ)
    public Paging<Map<String,Object>> findOperationLogs(int page, int count) {
        Paging<Map<String,Object>> paging = new Paging<>();

        List<Map<String,Object>> logList =
                operationLogMapper.queryOperationLogs(page>0?(page-1) * count:0,count);

        Long totalCount = operationLogMapper.queryLogCount();

        paging.setTotal(totalCount);
        paging.setItems(logList);

        return paging;
    }

    @Override
    @DataSource(name = DatasourceEnum.DATA_SOURCE_BIZ)
    public void saveOneOperationLog(VpnOperationLog operationLog) {
        //如果当前用户未登录，不做日志
        operationLogMapper.saveOneOperationLog(operationLog);
    }
}
